package com.micro.global;

import com.micro.entity.RequestHeader;
import com.micro.utils.SeriaUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author dufen
 */
@Slf4j
public class ConfigInfo {
    private static volatile com.micro.entity.ConfigInfo configInfo;
    private static boolean isShutdown;
    private static boolean isDormancy;
    private static boolean isReboot;
    public static final String VERSION = "0.1.9";
    static {
        try {
            configInfo = SeriaUtil.readObjectToFile("configInfo.obj", com.micro.entity.ConfigInfo.class);
            if (configInfo == null) {
                defaultConfig();
            }
        } catch (Exception e) {
            log.info("e:{}", e.getMessage());
            defaultConfig();
        }
    }

    public static com.micro.entity.ConfigInfo getConfigInfo() {
        return configInfo;
    }

    public static void setConfigInfo(com.micro.entity.ConfigInfo configInfo) {
        ConfigInfo.configInfo = configInfo;
    }

    public static boolean isIsShutdown() {
        return isShutdown;
    }

    public static void setIsShutdown(boolean isShutdown) {
        ConfigInfo.isShutdown = isShutdown;
    }

    public static boolean isIsDormancy() {
        return isDormancy;
    }

    public static void setIsDormancy(boolean isDormancy) {
        ConfigInfo.isDormancy = isDormancy;
    }

    public static boolean isIsReboot() {
        return isReboot;
    }

    public static void setIsReboot(boolean isReboot) {
        ConfigInfo.isReboot = isReboot;
    }

    public static void defaultConfig() {
        configInfo = new com.micro.entity.ConfigInfo();
        configInfo.setTries(255);
        configInfo.setTaskCoreSize(5);
        configInfo.setDownCoreSize(8);
        configInfo.setRequestHeader(new RequestHeader.Build().build());
        SeriaUtil.writeObjectToFile(configInfo, "configInfo.obj");
    }
}
